<%@ WebHandler Language="C#" Class="get_images" %>

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Web.SessionState;
using nStuff.ScriptSharp.Web.RestRpc;

public class get_images : RpcHandler, IReadOnlySessionState
{
	class ImageMsg
	{
		public string _name;
		public int _size;
		public DateTime _lastmod;
		public string _url;
		
		public string name
		{
			get { return _name;}
			set { _name = value; }
		}
		public int size
		{
			get { return _size;}
			set { _size = value; }
		}
		public DateTime lastmod
		{
			get { return _lastmod;}
			set { _lastmod = value; }
		}
		public string url
		{
			get { return _url; }
			set { _url = value; }
		}
	}
	
	[RpcMethod(RpcVerb.Get)]
	public Hashtable Get(string _dc)
	{
		string path = Context.Server.MapPath("./thumbs");
		
		List<ImageMsg> images = new List<ImageMsg>();
		DirectoryInfo di = new DirectoryInfo(path);
		FileInfo[] files = di.GetFiles("*.jpg");
		foreach (FileInfo file in files)
		{
			ImageMsg i = new ImageMsg();
			i.name = file.Name;
			i.lastmod = file.LastWriteTime;
			i.size = (int)file.Length;
			i.url = String.Format("./thumbs/{0}", file.Name);
			
			images.Add(i);
		}

		Hashtable msg = new Hashtable();
		msg["images"] = images.ToArray();
		return msg;
    }

}